import { createBrowserRouter } from "react-router-dom";
import { Navigate } from 'react-router-dom'

import Login from '@/views/login/login'
import Layout from '@/views/Layout/index'
import Welcome from '@/views/welcome/index'

import Error404 from '@/views/error/404'

import ZustandTest from '@/views/zustandTest'
import Dashboard from '@/views/dashboard'
import User from '@/views/system/user/index'
import UserDemo from '@/views/system/user/user'
import MapOrder from '@/views/mapOrder/index'
import Xrender from '@/views/xRender/index'

import AuthLoader from './AuthLoader'

const router = createBrowserRouter(
    [
        {
            path: "/",
            element: <Navigate to="/welcome"></Navigate>,
        },
        {
            path: "/login",
            element: <Login></Login>,
        },
        {   
            id: "layout",
            element: <Layout></Layout>,
            loader: AuthLoader,//拦截器
            children: [
                {
                    path: "/welcome",
                    element: <Welcome></Welcome>
                },
                {
                    path: "/zustandTest",
                    element: <ZustandTest></ZustandTest>,
                },
                {
                    path: "/dashboard",
                    element: <Dashboard></Dashboard>
                },
                {
                    path: "/system",
                    children: [
                        {
                            path: "user",
                            element: <User></User>
                        },
                        {
                            path: "userDemo",
                            element: <UserDemo></UserDemo>
                        },
                        {
                            path:"map",
                            element:<MapOrder></MapOrder>
                        },
                        {
                            path:"xrender",
                            element:<Xrender></Xrender>
                        }
                    ],

                },
            ]
        },
        {
            path: "/404",
            element: <Error404></Error404>,
        },
        {
            path: '*',
            element: <Navigate to={'/404'}></Navigate>
        }
    ],
);



export default router;